/******************************************************************************
 * (C) Copyright 2014 Atech-Automotive
 * FILE NAME:    APP_Can_Types.h
 * DESCRIPTION:
 * 
 * DATE BEGUN:   2014/08/10
 * BY:           martin.zhang
 * PRODUCT NAME:
 * APPLICATION:
 * TARGET H/W:
 * DOC REF:
 *****************************************************************************
 */                 

#ifndef _APP_CANTYPE_H_
#define _APP_CANTYPE_H_

/*****************************************************************************
** #include
*****************************************************************************/
#include"System.h"


/*****************************************************************************
** #define
*****************************************************************************/
#define CAN_PERIOD_2S              200  /*    2s in 10ms ticks */
#define CAN_PERIOD_1S              100  /*    1s in 10ms ticks */
#define CAN_PERIOD_500MS            50  /* 500ms in 10ms ticks */
#define CAN_PERIOD_200MS            20  /* 200ms in 10ms ticks */
#define CAN_PERIOD_100MS            10  /* 100ms in 10ms ticks */
#define CAN_PERIOD_50MS              5  /* 50ms in 10ms ticks */
#define CAN_PERIOD_20MS              2  /*  20ms in 10ms ticks */
#define CAN_PERIOD_10MS              1  /*  10ms in 10ms ticks */

#define RX_MSG_MAX_LEN 8
#define TX_MSG_MAX_LEN 8

/*****************************************************************************
**  typedef
*****************************************************************************/
typedef unsigned char  c_bool;
typedef unsigned char  c_u8;   
typedef unsigned int   c_u16;  
typedef unsigned long  c_u32;

/***************************** msg type ***************************************/
/*
 * can message type,
 * include normal,network management,diagnose
 */
typedef enum
{
    CAN_NORMAL = 0,
    CAN_NM,
    CAN_DIAG
}CAN_MSG_TYPE_E;

/*
 * can message send type,
 * include cycle, event, cycle&&event
 */
typedef enum
{
    CAN_CYCLE = 0,
    CAN_EVENT,
    CAN_CE
}CAN_MSG_SEND_TYPE_E;

/*
 * net module power type
 */
typedef enum
{
	POWER_30 = 0,
	POWER_15
}NODE_POWER_TYPE_E;

/*
 * can message tx struct
 */
typedef struct
{
            c_bool              Enable;     /* control the message active or inactive*/
    const   c_u32               Id;         /* can message identifier.      range:0x000~0x7FF*/
            c_u8                Length;     /* can message data length.     range:0~8*/
    const   CAN_MSG_TYPE_E      Type;       /* can message type.            range:normal,network management,diagnose*/
    const   CAN_MSG_SEND_TYPE_E SendType;   /* can message send type.       range:cycle(C), event(E), cycle&event(CE)*/
            c_bool              Trigger;    /* trigger the msg send,if msg SendType is E or CE*/
    const   c_u16               CycleTime;  /* cycle msg,send cycle time*/
            c_u16               CycleTimer; /* timer for CycleTime*/
            c_u8                Data[TX_MSG_MAX_LEN];/*can data, bit 7 of data[0] transmitted first */  
}CAN_TX_MSG_S;

/*
 * can message rx struct
 */
typedef struct
{
            c_bool              Enable;     /* control the message active or inactive*/
    const   c_u32               Id;         /* can message identifier.      range:0x000~0x7FF*/
            c_u8                Length;     /* can message data length.     range:0~8*/
    const   CAN_MSG_TYPE_E      Type;       /* can message type.            range:normal,network management,diagnose*/
    const   CAN_MSG_SEND_TYPE_E SendType;   /* can message send type.       range:cycle(C), event(E), cycle&event(CE)*/
    const   c_u16               CycleTime;  /* cycle msg,send cycle time*/
    const   c_u16               CycleTimeOut;/*timeout time to cycle msg*/
            c_u16               CycleTimer; /* timer for CycleTimeOut*/
    const   NODE_POWER_TYPE_E   PowerType;  /* net module power type*/
            c_bool              Error;      /*it's true if the msg timeout*/
            c_bool              UpdataState;/*it's true if receive the msg*/
            c_u8                Data[RX_MSG_MAX_LEN];/* can data, bit 7 of data[0] transmitted first */
    const   c_u8                InitData[RX_MSG_MAX_LEN];/*can init data*/
            c_u8                LastData[RX_MSG_MAX_LEN];/*can last data*/    
}CAN_RX_MSG_S;

/***************************** driver *****************************************/
/*
 * can message base struct
 */
typedef struct {
    UINT32 u32_msgId;
    UINT8  u8_dlc;
    UINT8  u8_data[8];
}DRV_CAN_MSG_S; 

/*
 * can frame type
 */
 typedef enum
{    
    CAN_STANDARD_ID = 0,
    CAN_EXTEND_ID
}CAN_FRAME_TYPE_E;

/*
 * can state
 */
typedef enum {
    CAN_SUCCESS = 0,
    CAN_ERROR,
    CAN_PARAM_ERROR,
    CAN_INIT_ERROR,
    CAN_TX_BUFFER_FULL,   
    CAN_BUS_LIMPHOME, 
}CAN_STATE_E;

/*
 * can bus state
 */
typedef enum{
    CAN_BUS_ERROR_ACTIVE = 0,
    CAN_BUS_ERROR_PASSIVE,
    CAN_BUS_BUSOFF,
}CAN_BUS_STATE_E;

/*
 * interrupt CMD
 */
typedef enum{
    RX_INT = 0,
    TX_INT,
    WAKEUP_INT,
    ERROR_INT,
    OVR_INT
}CAN_INT_CONGIF_CMD_E;


/******************************** NWM *****************************************/
/*
 * NWM can bus state
 */
typedef enum 
{
	CAN_NWM_BUS_NORMAL = 0,
	CAN_NWM_BUS_HOLD,
	CAN_NWM_BUS_OFF
}CAN_NWM_BUS_STATE_E;

/*
 * notify can Nwm command
 */
typedef enum
{
    CMD_CAN_NWM_WAKE_UP = 0,
    CMD_CAN_NWM_BUS_OFF,
    CMD_CAN_NWM_RECEIVED,
    CMD_CAN_NWM_QUICK_SLEEP
}NOTIFY_CAN_NWM_CMD_E;

/****************************************************************************/

#endif	//_APP_CAN_TYPES_H_

/*****************************************************************************
** End File
*****************************************************************************/

